#!/bin/bash

# ## Debug Test
# [ -e /tmp/a.txt ] && echo yes || echo no
# [ -d /home ] && echo yes || echo no
#
# [ -d ~ ] && echo yes || echo no
# [ -d ~/.SpaceVim ] && echo yes || echo no
# [ -d ~/.SpaceVim/.git ] && echo yes || echo no
#
# pathValues=~/.SpaceVim
# gitpathValues=${pathValues}"/.git"
# echo ${gitpathValues}
# [ -d ${pathValues} ] && echo yes || echo no
# [ -d ${gitpathValues} ] && echo yes || echo no

# 获取当前脚本目录位置
cd `dirname $0`
curdir=`pwd`
echo ${curdir}


echo "[INFO] git clone https://github.com/SpaceVim/SpaceVim.git ~"
SpaceVimSrcPath=~/.SpaceVim
if [ -d ${SpaceVimSrcPath} ] && [ -d ${SpaceVimSrcPath}"/.git" ]
then
	# echo yes
	cd ${SpaceVimSrcPath}
	git pull

else
	# echo no
	# git clone https://github.com/SpaceVim/SpaceVim.git
	git clone https://gitee.com/SpaceVim/SpaceVim.git ~
fi


mv ~/.SpaceVim.d  ~/.SpaceVim.d-bak`date +%y%m%d%H%M%S`
mv ~/.vimrc  ~/.vimrc-bak`date +%y%m%d%H%M%S`
mv ~/.vim  ~/.vim-bak`date +%y%m%d%H%M%S`

# 建立软链接命令拼接
cmdStr="ln -s  "${curdir}"/MySpaceVim  "${HOME}"/.SpaceVim.d"
echo "执行命令: ${cmdStr} 建立软链接"
${cmdStr}

cmdStr="ln -s  "${HOME}"/.SpaceVim  "${HOME}"/.vim"
echo "执行命令: ${cmdStr} 建立软链接"
${cmdStr}
